/*
 * Java Parallel Processing Framework.
 *  Copyright (C) 2005-2009 JPPF Team. 
 * http://www.jppf.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	 http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.whereiswally.faint;

import java.io.FileInputStream;

import org.apache.commons.io.IOUtils;
import org.jppf.client.JPPFClient;
import org.jppf.client.JPPFJob;
import org.whereiswally.fwkexamples.jppf.test.ResultListener;

/**
 * Runner for the hello world application.
 * 
 * @author Laurent Cohen
 */
public class FaintTestRunner {
    /**
     * Entry point.
     * 
     * @param args
     *            not used.
     */
    public static void main(String... args) {
	JPPFClient client = null;
	try {
	    client = new JPPFClient();
	    JPPFJob job = new JPPFJob();

	    // byte[] wally=IOUtils.toByteArray(new
	    // FileInputStream("C:\\Data\\workspace\\Wally\\resource\\faces\\jpg\\ID01_001.jpg"));
	    // byte[] wallyCT=IOUtils.toByteArray(new
	    // FileInputStream("C:\\Data\\workspace\\Wally\\resource\\faces\\jpg\\ID01_001_B.jpg"));

	    byte[] wally = IOUtils.toByteArray(new FileInputStream(
		    "resource/faces/jpg/ID01_001.jpg"));
	    byte[] wallyCT = IOUtils.toByteArray(new FileInputStream(
		    "resource/faces/jpg/ID01_001_B.jpg"));

	    job.addTask("run", new FaintTest(), wally, wallyCT);
	    // job.addTask("test", new FaintTest());
	    //
	    // List<JPPFTask> results = client.submit(job);
	    // System.out.println("********** Results: **********");
	    // for (JPPFTask task : results) {
	    // if (task.getException() != null) {
	    // StringWriter sw = new StringWriter();
	    // task.getException().printStackTrace(new PrintWriter(sw));
	    // System.out.println(sw.toString());
	    // } else
	    // System.out.println("" + task.getResult());
	    // }

	    client
		    .submitNonBlocking(job.getTasks(), null,
			    new ResultListener());

	    /*
	     * JPPFClientConnectionImpl c = (JPPFClientConnectionImpl) client
	     * .getClientConnection("driver1"); // query the driver's JMX server
	     * for the attached nodes Collection<NodeManagementInfo> nodeList =
	     * c.getJmxConnection() .nodesInformation();
	     * 
	     * JMXNodeConnectionWrapper jmxClient = new
	     * JMXNodeConnectionWrapper( "", 1); // perform the actual
	     * connection to the JMX server jmxClient.connect(); // Stop the
	     * node - this will effectively terminate the remote node // process
	     * jmxClient.shutdown();
	     */

	} catch (Exception e) {
	    e.printStackTrace();
	} finally {
	    // if (client != null)
	    // client.close();
	}
	// System.exit(0);
    }
}
